/**
 * 实验对照登记管理初始化
 */
var TestRegist = {
    id: "TestRegistTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
TestRegist.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '对照编号', field: 'testId', visible: true, align: 'center', valign: 'middle'},
            {title: '标准物质标识码', field: 'testStandardCode', visible: true, align: 'center', valign: 'middle'},
            {title: '对照品标识码', field: 'testCode', visible: true, align: 'center', valign: 'middle'},
            {title: '实验时间', field: 'testTime', visible: true, align: 'center', valign: 'middle'},
            {title: '使用编号', field: 'useId', visible: true, align: 'center', valign: 'middle'},
            {title: '检验目的', field: 'testPurpose', visible: true, align: 'center', valign: 'middle'},
            /*{title: '是否预处理', field: 'testPretreatment', visible: true, align: 'center', valign: 'middle'},
            {title: '预处理', field: 'testPretreatmentYn', visible: true, align: 'center', valign: 'middle'},*/
            {title: '备注', field: 'testRemarks', visible: true, align: 'center', valign: 'middle'}

    ];
};

/**
 * 检查是否选中
 */
TestRegist.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        TestRegist.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加实验对照登记
 */
TestRegist.openAddTestRegist = function () {
    var index = layer.open({
        type: 2,
        title: '添加实验对照登记',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/testRegist/testRegist_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看实验对照登记详情
 */
TestRegist.openTestRegistDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '实验对照登记详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/testRegist/testRegist_update/' + TestRegist.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除实验对照登记
 */
TestRegist.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/testRegist/delete", function (data) {
            Feng.success("删除成功!");
            TestRegist.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("testRegistId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询实验对照登记列表
 */
TestRegist.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    TestRegist.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = TestRegist.initColumn();
    var table = new BSTable(TestRegist.id, "/testRegist/list", defaultColunms);
    table.setPaginationType("client");
    TestRegist.table = table.init();
});
